package JavaTest.encapsulation;

public class Person {
    /**姓名公开*/
    public String name;
    /**年龄：不可修改*/
    private int age;
    /**私有化*/
    private int salary;

    public Person(String name, int age, int salary) {
        setAge(age);
        setName(name);
        setSalary(salary);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name.length() > 12){
            return;
        }
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age > 120 || age < 0){
            this.age = 18;
            return;
        }
        this.age = age;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }
}
